﻿#region Librerias
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
#endregion

/// <summary>
/// Class Program, define las interfaces existentes en la aplicacion
/// </summary>

#region Class

public class clsWorkArea : DAC
{
    #region Variables

    private int idWorkArea;
    private String sName;
    private const String tabla = "dbo.tblWorkArea";

    #endregion

    #region Builder

    /// <summary>
    /// Constructor
    /// </summary>
    public clsWorkArea() { }

    #endregion

    #region Methods

    #region Consultations

    public DataSet SeeAllTheRecords()
    {
        String query = "SELECT row_number() over(order by " + tabla + ".idWorkArea) As NUMBER, ";
        query += tabla + ".idWorkArea As ID, " + tabla + ".sName As NAME ";
        query += "FROM " + tabla;
        return this.ExecuteQuery(query);
    }

    public DataSet SeeAllTheRecords(int startRecord, int maxRecord, String text)
    {
        String query = "SELECT row_number() over(order by " + tabla + ".idWorkArea) As NUMBER, ";
        query += tabla + ".idWorkArea As ID, " + tabla + ".sName As NAME ";
        query += "FROM " + tabla;
        if (!text.Equals(""))
        {
            query += " WHERE " + tabla + ".sName LIKE '%" + text + "%' ";
        }
        if (startRecord == 0 && maxRecord == 0)
        {
            return this.ExecuteQuery(query);
        }
        else
        {
            return this.ExecuteQuery(query, startRecord, maxRecord);
        }
    }

    public DataSet ConsultID(String id)
    {
        String query = "SELECT ";
        query += tabla + ".idWorkArea As ID, " + tabla + ".sName As NAME ";
        query += "FROM " + tabla;
        query += " WHERE " + tabla + ".idWorkArea =" + id;
        return this.ExecuteQuery(query);
    }

    #endregion

    public int Insert()
    {
        String query = "INSERT INTO " + tabla;
        query += "(sName) ";
        query += "VALUES ('{0}')";

        String sql = String.Format(query, this.SName);
        return this.ExecuteDML(sql, "no");
    }

    public int Update()
    {
        String query = "UPDATE " + tabla + " SET ";
        query += tabla + ".sName='" + this.SName + "' ";
        query += "WHERE ";
        query += tabla + ".idWorkArea=" + this.ID;
        return this.ExecuteDML(query, "no");
    }

    public int Delete()
    {
        String query = "DELETE FROM " + tabla + " WHERE " + tabla + ".idWorkArea={0}";
        String sql = String.Format(query, this.ID);
        return this.ExecuteDML(sql, "no");
    }

    #endregion

    #region Setters and Getters

    public int ID
    {
        get { return idWorkArea; }
        set { idWorkArea = value; }
    }

    public String SName
    {
        get { return sName; }
        set { sName = value; }
    }

    #endregion

}

#endregion